package com.hua.yuan.live.view.holder_view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.hua.yuan.common.BaseHolderView;
import com.hua.yuan.live.R;
import com.hua.yuan.live.listener.OnBuyClickListener;
import com.hua.yuan.live.repertory.cloud_data.res.GroupChat;

import java.util.List;

/**
 * 直播列表的ITEM
 */
public class HolderView_PublicChat implements BaseHolderView<GroupChat>,View.OnClickListener{


    private TextView tvUserName;
    private TextView tvContent;
    private TextView tvType;

    private int mPosition;

    private OnBuyClickListener mOnBuyClickListener;

    public HolderView_PublicChat(View pView, int pPosition) {

        tvUserName=pView.findViewById(R.id.tv_username_live_room);
        tvContent=pView.findViewById(R.id.tv_content_live_room);
        tvType=pView.findViewById(R.id.tv_vip_live_room);
    }


    public void bindHolder(@NonNull List<GroupChat> pList, int position, @NonNull Context pContext) {

        if (pList == null || pList.size() == 0 || (position > pList.size())) {
            return;
        }

        GroupChat groupChat = pList.get(position);
        if (groupChat == null) {
            return;
        }
        //直播时间
        String content = groupChat.getContent();
        String userName=groupChat.getUserName();
        String regx=pContext.getResources().getString(R.string.user_live_room);
        tvUserName.setText(String.format(regx,userName));
        tvContent.setText(content);
        switch (groupChat.getType()){
            case 1:
                tvType.setText("VIP");
                break;
            case 2:
                tvType.setText("红包");
                break;
        }

    }


    @Override
    public void onClick(View v) {

        if(R.id.iv_anchor_img_live_history ==v.getId()){

            mOnBuyClickListener.click(mPosition);

        }
    }
}
